<?php

use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Form\Field\Editor;
use Dcat\Admin\Grid\Filter;
use Dcat\Admin\Show;

/**
 * Dcat-admin - admin builder based on Laravel.
 * @author jqh <https://github.com/jqhph>
 *
 * Bootstraper for Admin.
 *
 * Here you can remove builtin form field:
 *
 * extend custom field:
 * Dcat\Admin\Form::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
 *
 * Or require js and css assets:
 * Admin::css('/packages/prettydocs/css/styles.css');
 * Admin::js('/packages/prettydocs/js/main.js');
 *
 */

app('view')->prependNamespace('admin', resource_path('views/admin'));

// 列表-公共设置
Grid::resolving(function (Grid $grid) {
    $grid->disableRowSelector();
    $grid->actions(function (Grid\Displayers\Actions $actions) {
        $actions->disableView();
        $actions->disableDelete();
    });

});

// 表单-公共设置
Form::resolving(function (Form $form) {
     $form->disableEditingCheck();
     $form->disableCreatingCheck();
     $form->disableViewCheck();

     $form->tools(function (Form\Tools $tools) {
          $tools->disableDelete();
          $tools->disableView();
     });

});

// 详情-公共设置
Show::resolving(function (Show $show) {
    Admin::script(<<<EOL
$('.content-body .box-header').addClass('fix-box-header');
EOL);

    $show->disableEditButton();
    $show->disableDeleteButton();
});

// 列表-列扩展
Grid\Column::extend('preview', function ($value, $text = '查看') {
    return "<a href='$value' target='_blank'>$text</a>";
});

// 表单-编辑器公共设置
Editor::resolving(function (Editor $editor) {
    $editor->imageDirectory(config('admin.upload.directory.editor'))
        ->options([
            'plugins' => [
                'advlist', 'autolink', 'image', 'media', 'lists', 'preview', 'code', 'help',
                'fullscreen', 'table', 'autoresize', 'codesample', 'wordcount', 'wordlimit',
            ],
        ])->help('上传图片请使用工具栏图片按钮上传');
});

// 表单-图片公共设置
Form\Field\Image::resolving(function (Form\Field\Image $image) {
    $image->downloadable()->uniqueName()->autoUpload()->retainable()->saveFullUrl()
        ->removable(false)->maxSize(20 * 1024);
});
Form\Field\MultipleImage::resolving(function (Form\Field\MultipleImage $image) {
    $image->downloadable()->uniqueName()->autoUpload()->retainable()->saveFullUrl()
        ->removable(false)->maxSize(20 * 1024)->sortable();
});

// 表单-文件公共设置
Form\Field\File::resolving(function (Form\Field\File $file) {
    $file->downloadable()->uniqueName()->autoUpload()->retainable()->saveFullUrl()
        ->removable(false)->maxSize(500 * 1024)->width(6);
});
Form\Field\MultipleFile::resolving(function (Form\Field\MultipleFile $file) {
    $file->downloadable()->uniqueName()->autoUpload()->retainable()->saveFullUrl()
        ->removable(false)->maxSize(500 * 1024);
});
